<template>
  <div style='margin-bottom: 50px;'>
    <!--答题时间设置-->
    <a-popover title='作用' placement='topLeft'>
      <template slot='content'>
        <p>将高于分数线的用户则录取状态设置为
          <a-tag color='green'>已录取</a-tag>
          (系统自动)
        </p>
        <p>对低于分数线的用户则录取状态设置为
          <a-tag color='red'>未录取</a-tag>
          (系统自动)
        </p>
      </template>
      <a-divider orientation='left'>最低通过分数线设置</a-divider>
    </a-popover>
    
    <a-form
      layout='inline'
      :form='form'
      @submit='handleSubmit'>
      
      
      <a-form-item label='最低通过分数线'>
        <a-input-number
          :max='100'
          :min='5'
          style='width: 100%;'
          v-decorator="['scoreLine', { initialValue:scoreLine, rules: [{ required: true, message: '最低通过分数线不能为空' }] },]"
        />
      </a-form-item>
      
      <a-form-item>
        <a-space>
          <a-button @click='() => this.form.resetFields()'>重置</a-button>
          <a-button type='primary'
                    @click='showConfirm'
                    :loading='loading'>确认
          </a-button>
        </a-space>
      </a-form-item>
    
    </a-form>
  
  </div>
</template>

<script>
import { setScoreLine, getScoreLine } from '@/api/systemConfig'

export default {
  name: 'ScoreLine',
  data() {
    return {
      scoreLine: null,
      loading: false,
      form: this.$form.createForm(this, { name: 'scoreLine' })
    }
  },
  created() {
    this.getScoreLine()
  },
  methods: {
    showConfirm() {
      this.form.validateFields((err, values) => {
        if (!err) {
          let fieldsValue = this.form.getFieldsValue()
          let than = this
          this.$confirm({
            title: '确认修改最低通过分数线',
            width: 500,
            content: h =>
              <div style='color:red;'>
            <span>
              最低通过分数线 : &nbsp;&nbsp; {fieldsValue.scoreLine}
            </span>
                <br />
              </div>,
            onOk() {
              than.handleSubmit()
            },
            onCancel() {
            },
            class: 'test'
          })
        }
      })
    },
    handleSubmit() {
      this.loading = true
      this.form.validateFields((err, values) => {
        if (!err) {
          // 设置分数线时间
          setScoreLine(values).then(() => {
            this.$message.success('设置成功')
            this.getScoreLine()
          })
        }
      })
      this.loading = false
    },
    // 获取分数线
    getScoreLine() {
      getScoreLine().then(response => {
        this.scoreLine = response.data.scoreLine
      })
    }
  }
}
</script>

<style scoped>

</style>